package com.ruoyi.appService.mentalTestResult.mbtiResult.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.appService.mentalTestResult.mbtiResult.domain.ZTestMbtiTestresult;
import com.ruoyi.appService.mentalTestResult.mbtiResult.service.IZTestMbtiTestresultService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * mbti测试结果Controller
 * 
 * @author anjiao
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/mentalTest/mbtiTestResult")
public class ZTestMbtiTestresultController extends BaseController
{
    @Autowired
    private IZTestMbtiTestresultService zTestMbtiTestresultService;

    /**
     * 查询mbti测试结果列表
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mbtiTestResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZTestMbtiTestresult zTestMbtiTestresult)
    {
        startPage();
        List<ZTestMbtiTestresult> list = zTestMbtiTestresultService.selectZTestMbtiTestresultList(zTestMbtiTestresult);
        return getDataTable(list);
    }

    /**
     * 导出mbti测试结果列表
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mbtiTestResult:export')")
    @Log(title = "mbti测试结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZTestMbtiTestresult zTestMbtiTestresult)
    {
        List<ZTestMbtiTestresult> list = zTestMbtiTestresultService.selectZTestMbtiTestresultList(zTestMbtiTestresult);
        ExcelUtil<ZTestMbtiTestresult> util = new ExcelUtil<ZTestMbtiTestresult>(ZTestMbtiTestresult.class);
        util.exportExcel(response, list, "mbti测试结果数据");
    }

    /**
     * 获取mbti测试结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mbtiTestResult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zTestMbtiTestresultService.selectZTestMbtiTestresultById(id));
    }

    /**
     * 新增mbti测试结果
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mbtiTestResult:add')")
    @Log(title = "mbti测试结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZTestMbtiTestresult zTestMbtiTestresult)
    {
        return toAjax(zTestMbtiTestresultService.insertZTestMbtiTestresult(zTestMbtiTestresult));
    }

    /**
     * 修改mbti测试结果
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mbtiTestResult:edit')")
    @Log(title = "mbti测试结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZTestMbtiTestresult zTestMbtiTestresult)
    {
        return toAjax(zTestMbtiTestresultService.updateZTestMbtiTestresult(zTestMbtiTestresult));
    }

    /**
     * 删除mbti测试结果
     */
    @PreAuthorize("@ss.hasPermi('mentalTest:mbtiTestResult:remove')")
    @Log(title = "mbti测试结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zTestMbtiTestresultService.deleteZTestMbtiTestresultByIds(ids));
    }





// 给小程序端提供的新增或修改测试结果
//根据用户id判断是否是添加还是修改
    @PostMapping("addOrUpdate")
    public AjaxResult addOrupdateMbtiTestResult(@RequestBody ZTestMbtiTestresult zTestMbtiTestresult, HttpServletRequest request)
    {
        zTestMbtiTestresultService.addOrupdateMbtiTestResult(zTestMbtiTestresult,request);
        return AjaxResult.success(  );
    }




//    查询测试结果根据用户id
@PostMapping("selectTestResult")
public AjaxResult selectTestResult( HttpServletRequest request)
{
    return zTestMbtiTestresultService.selectTestResult(request);
}






}
